﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Rarous.TexyNet.Parser.Elements {
  public class Element {
    #region Fields
    private ElementType _elementType;
    private Modifier _modifier;
    private readonly IList<Element> _childElements;
    private string _text;
    #endregion

    #region Constructors
    public Element()
      : this(ElementType.Literal) {
    }

    public Element(ElementType elementType) 
      : this(elementType, String.Empty) {
    }

    public Element(ElementType elementType, string text) {
      _elementType = elementType;
      _modifier = new Modifier();
      _childElements = new List<Element>();
      _text = text;
    }
    #endregion

    #region Properties
    public ElementType ElementType {
      get {
        return _elementType;
      }
      set {
        _elementType = value;
      }
    }

    public Modifier Modifier {
      get {
        return _modifier;
      }
      set {
        _modifier = value;
      }
    }

    public ReadOnlyCollection<Element> ChildElements {
      get {
        return new ReadOnlyCollection<Element>(_childElements);
      }
    }

    public string Text {
      get {
        return _text;
      }
      set {
        _text = value;
      }
    }
    #endregion
    
    public void AppendChildElement(Element child) {
      _childElements.Add(child);
    }
  }
}